/**
 * author:Administrator
 * date:2016/3/2
 * desc:TODO
 */
"use strict";

var app = require('koa')();
var config = require('./config');

// ---logger
app.use(function*(next) {
  var start = new Date();
  yield next;
  var ms = new Date() - start;
  console.log('%s %s - %s', this.method, this.url, ms);
});

// ---enable cross domain
var cors = require('koa-cors'); //解决跨域
app.use(cors({credentials: true}));

// ---------------router-----------
app.use(require('./router/v1/location.js'));
app.use(require('./router/v1/category.js'));
app.use(require('./router/v1/user.js'));
app.use(require('./router/v1/role.js'));
// ---------------router-----------

// 404
app.use(function*() {
  this.status = 404;
  this.body = '~~~404 not found~~~';
});

app.listen(config.port, config.host, function () {
  console.log('server listen at %s:%s', config.host, config.port);
});